<?php
class Share_media extends CI_Model {

    function __construct(){
        parent::__construct();
    }


    function addVideo($videoID,$title,$desc,$thumb,$identifier) {

        $data = array(
          'video_id' => $videoID,
          'user_id' => $this->input->cookie('LEAPSESSID'),
          'title' => $title,
          'description' => $desc,
          'thumb' => $thumb,
          'identifier' => $identifier
        );
        $insert = $this->mongo_db->insert('videos', $data);
    }
    function getVideos(){
        $page = 1*50;
        $query = $this->mongo_db->offset($page)->get('videos');
        return $query;
    }
    function editVideoInfos(){
        
    }
    function rand_string( $length ) {
	$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $str ='';
	$size = strlen( $chars );
	for( $i = 0; $i < $length; $i++ ) {
		$str .= $chars[ rand( 0, $size - 1 ) ];
	}

	return $str;
    }
    function addImage($photoID,$name,$source,$thumb,$width,$height,$uploaded,$timestamp){
        $data = array(
          'photo_id' => $photoID,
          'originale' => $name,
          'thumb' => $thumb,
          'user_id' => $this->input->cookie('LEAPSESSID'),
          'title' => "",
          'width' => $width,
          'height' => $height,
          'description' => "",
          'source' => $source,
          'spot' => '',
          'uploaded' => $uploaded,
          'timestamp' => $timestamp
        );
        $insert = $this->mongo_db->insert('photos', $data);
    }
    function editImageInfos($photo_id,$title,$desc,$spot){
        $data = array(
          'title' => $title,
          'description' => $desc,
          'spot' => $spot
        );
        $this->mongo_db->where('photo_id' , $photo_id);
        $query = $this->mongo_db->set($data)->update('photos');
        return $query;
    }

    function add500pxImage($id,$source,$thumb,$title,$desc,$spot,$uploaded,$timestamp){
        $data = array(
          'photo_id' => $id,
          'user_id' => $this->input->cookie('LEAPSESSID'),
          'title' => $title,
          'thumb' => $thumb,
          'description' => $desc,
          'source' => $source,
          'spot' => $spot,
          'uploaded' => $uploaded,
          'timestamp' => $timestamp
        );
        $insert = $this->mongo_db->insert('photos', $data);
        if($insert){
            return 1;
        }
    }
    function getPhotos(){
        $query = $this->mongo_db->get('photos');
        return $query;
    }
    function getPhoto($photo_id){
        $this->mongo_db->where('photo_id' , $photo_id);
        $query = $this->mongo_db->get('photos');
        return $query;
    }
}
?>